package com.jader.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jader.beans.Goods_comment;
import com.jader.util.JaderApplication;
import com.lidroid.xutils.BitmapUtils;
import com.zlp.jader.R;

public class GoodsEvaluteAdapter extends BaseAdapter {
	private List<Goods_comment> list;
	private Context context;
	private LayoutInflater mInflater;
	private ViewHolder mHolder;
	private BitmapUtils bitmapUtils;

	public GoodsEvaluteAdapter(List<Goods_comment> list, Context context) {
		super();
		this.list = list;
		this.context = context;
		bitmapUtils = JaderApplication.getBitmapUtils();
		mInflater = LayoutInflater.from(this.context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		if (arg1 == null) {
			arg1 = mInflater.inflate(R.layout.adapter_goods_evalute, null);
			mHolder = new ViewHolder();
			mHolder.username = (TextView) arg1
					.findViewById(R.id.evalute_username);
			mHolder.content = (TextView) arg1
					.findViewById(R.id.evalute_user_content);
			mHolder.time = (TextView) arg1.findViewById(R.id.evalute_user_time);
			mHolder.picture = (ImageView) arg1
					.findViewById(R.id.evalute_user_picture);
			arg1.setTag(mHolder);
		} else {
			mHolder = (ViewHolder) arg1.getTag();
		}
		mHolder.username.setText(list.get(arg0).getUser().getUsername());
		mHolder.content.setText(list.get(arg0).getEvalute().getContent());
		mHolder.time.setText("发表于：" + list.get(arg0).getEvalute().getTime());
	
		bitmapUtils.display(mHolder.picture, JaderApplication.getIP()
				+"/Jader"+ list.get(arg0).getUser().getPicture());
		return arg1;
	}

	class ViewHolder {
		TextView username, content, time;
		ImageView picture;
	}

}
